package com.decode;

/**
 * Created by Administrator on 2016/8/2 0002.
 */
public class Coding {

    public byte[] request(byte cmd) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x00;
        data[1] = cmd;
        return data;
    }

    public byte[] speed(short left, short right) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x02;
        data[1] = (byte) (left >> 8);
        data[2] = (byte) left;
        data[3] = (byte) (right >> 8);
        data[4] = (byte) right;
        return  data;
    }

    public byte[] lightBelt(byte cmd) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x08;
        data[1] = cmd;
        return data;
    }

    public byte[] shutDown(byte delay) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x0a;
        data[1] = delay;
        return data;
    }

    public byte[] charge(byte cmd) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x0c;
        data[1] = cmd;
        return data;
    }

    public byte[] pid(byte kp,byte ki,byte kd) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = (byte)0xf0;
        return data;
    }

    public byte[] flag(boolean isDebug,boolean isEnable,boolean isAuto,boolean isReturn,boolean isCloseLoop) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = (byte)0x50;
        if (isDebug) data[1] = (byte)0x01;
        else data[1] = (byte)0x00;
        if (isEnable) data[2] = (byte)0x01;
        else data[2] = (byte)0x00;
        if (isAuto) data[3] = (byte)0x01;
        else data[3] = (byte)0x00;
        if (isReturn) data[4] = (byte)0x01;
        else data[4] = (byte)0x00;
        if (isCloseLoop) data[5] = (byte)0x01;
        else data[5] = (byte)0x00;
        return data;
    }

    public byte[] flag(boolean isDebug,boolean isEnable,boolean isAuto,boolean isReturn,boolean isCloseLoop,boolean isRefresh) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = (byte)0x50;
        if (isDebug) data[1] = (byte)0x01;
        else data[1] = (byte)0x00;
        if (isEnable) data[2] = (byte)0x01;
        else data[2] = (byte)0x00;
        if (isAuto) data[3] = (byte)0x01;
        else data[3] = (byte)0x00;
        if (isReturn) data[4] = (byte)0x01;
        else data[4] = (byte)0x00;
        if (isCloseLoop) data[5] = (byte)0x01;
        else data[5] = (byte)0x00;
        if (isRefresh) data[6] = (byte)0x01;
        else data[6] = (byte)0x00;
        return data;
    }

    public byte[] SPD2Client(short left, short right) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x51;
        data[1] = (byte) (left >> 8);
        data[2] = (byte) left;
        data[3] = (byte) (right >> 8);
        data[4] = (byte) right;
        return  data;
    }

    public byte[] control(int setCenter,int setDir) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = (byte)0x52;
        data[1] = (byte) setCenter;
        data[2] = (byte) setDir;
        return  data;
    }

    public byte[] PID(short kp,short ki,short kd) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = (byte)0x57;
        data[1] = (byte) (kp >> 8);
        data[2] = (byte) kp;
        data[3] = (byte) (ki >> 8);
        data[4] = (byte) ki;
        data[5] = (byte) (kd >> 8);
        data[6] = (byte) kd;
        return data;
    }

    public byte[] optimize(short k_id, short value) {
        byte [] data = {0,0,0,0, 0,0,0,0};
        data[0] = 0x5a;
        data[1] = (byte) (k_id >> 8);
        data[2] = (byte) k_id;
        data[3] = (byte) (value >> 8);
        data[4] = (byte) value;
        return  data;
    }
}
